package com.cskaoyan.javase.basic._7flow._1selective;

import java.util.Scanner;

/**
 * @description: 选择结构
 * @author: wuguidong@cskaoyan.onaliyun.com
 **/

public class Demo {
    public static void main(String[] args) {
        /*//使用if需要注意的细节: 尽量能够把if写得更加的简洁和优雅,尽量不带大括号
        System.out.println("请键盘录入一个数字:");
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        if (a > 0) System.out.println("a是一个大于0的数");
        else  System.out.println("a是一个不大于0的数");*/

        //键盘录入月份的值，输出对应的季节
        System.out.println("请输入月份:");
        Scanner sc = new Scanner(System.in);

        /**
         * switch的执行如何结束?
         * 当某个分支匹配上后,会执行分支中代码,直到switch结束或者碰到一个break
         * break表示结束当前switch
         * switch的这种特点就是所谓的case穿越
         *
         */while (true) {
            int month = sc.nextInt();
            switch (month) {
                case 12:
                case 1:
                    System.out.println("冬天");
                case 2:
                    break;
                case 3:
                case 4:
                case 5:
                    System.out.println("春天");
                    break;
                case 6:
                case 7:
                case 8:
                    System.out.println("夏天");
                    break;
                case 9:
                case 10:
                case 11:
                    System.out.println("秋天");
                    break;
                //当输入错误月份时,提供一个通配的选项,相当于if..else中的最后一个else
                default:
                    System.out.println("输入错误!!~~");
            }
        }
        //Unreachable statement
        /*int x = 2;
        int y = 3;
        switch (x) {
            default:
                y++;
                //Switch label 'case 3:' is unreachable
            case 3:
                y++;
            case 4:
                y++;
        }
        System.out.println("y=" + y);*/
    }
}
